package org.jinyan.quartz.example.scheduler;

import java.util.Date;

import org.jinyan.quartz.example.job.HelloJob;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class CronTriggerSchedulerDemo {

	public void run() throws Exception {
		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler sch = sf.getScheduler();
		JobDetail job = JobBuilder.newJob(HelloJob.class)
				.withIdentity("jobName", "groupName").build();
		CronTrigger trigger = (CronTrigger) TriggerBuilder
				.newTrigger()
				.withIdentity("triggerName", "groupName")
				.withSchedule(
						CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
				.build();
		Date df =sch.scheduleJob(job, trigger);
		System.err.println(df);

		sch.start();
	}

	public static void main(String[] args) throws Exception {
		new CronTriggerSchedulerDemo().run();
	}

}
